<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">

    <title></title>
    <style>
        * {
            margin: auto;
        }

        #textBox {
            padding: 10px;
            height: 300px;
            border-color: #003C9D;
        }
        #contentLength{

          margin-right: 2%;
          text-align: right;
          color:#20B2AA;
          font-size: 0.95rem;
        }
        #textBox{
          zoom:1;
          overflow: hidden;

          /*padding-top: 10px!important;*/

        }
        #text{
          padding-top: 10px;
          margin-bottom: 10px;
          width:98%;
          height:96%;
          border-radius:3px;
          text-indent: 1rem;
          border: 1px solid #20B2AA;
        }
    </style>
</head>

<body style="background-color:#white;">
    <div id="textBox">
        <textarea maxlength="100" placeholder="···编辑内容(限200字符)" id="text" name="text" value=""></textarea>
    </div>
    <div id="contentLength">0/200</div>
    <div style="width:90%;margin-top:20px;color:#20B2AA;">是否设置提醒:&nbsp;<input type="radio" id="s" value="true" name="a" onclick="showTime()">是</input><input type="radio" id="d" onclick="closeTime()" value="false" name="a" checked="checked">否</input>
    </div>
    <div id="w" style="width:90%;margin-top:20px;display:none;color:#20B2AA;">设置提醒时间:&nbsp;<input type="datetime-local" id="remind" value="" /></div>
    <div style="margin-top:20px;"><input type="button" value="添加至备忘录" style="border:0;border-radius:5px;font-size:16px;color:#FFFFFF;width:100%;height:45px;background-color:#03a9f4;" onclick="sure()" /></div>


    <script>
        function showTime() {
            document.getElementById('w').style.display = 'block';
            var now = new Date();
            var y = now.getFullYear(),
                m = ("0" + (now.getMonth() + 1)).slice(-2),
                d = ("0" + now.getDate()).slice(-2);
            var h = now.getHours(),
                mm = now.getMinutes(),
                s = now.getSeconds();
            var today = y + "-" + m + "-" + d + "T" + h + ":" + mm + ":" + s;
            $('#remind').val(today);

        }

        function closeTime() {
            document.getElementById('w').style.display = 'none';
        }
    </script>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/properties.js"></script>
<script type="text/javascript">
    apiready = function() {
        api.parseTapmode();
    };
</script>
<script>
    function sure() {

        //时间转换
        Date.prototype.format = function(format) {
            var date = {
                "MM+": this.getMonth() + 1,
                "dd+": this.getDate(),
                "hh+": this.getHours(),
                "mm+": this.getMinutes(),
                "ss+": this.getSeconds(),
                "q+": Math.floor((this.getMonth() + 3) / 3),
                "S+": this.getMilliseconds()
            };
            if (/(y+)/i.test(format)) {
                format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
            }
            for (var k in date) {
                if (new RegExp("(" + k + ")").test(format)) {
                    format = format.replace(RegExp.$1, RegExp.$1.length == 1 ?
                        date[k] : ("00" + date[k]).substr(("" + date[k]).length));
                }
            }
            return format;
        };



        var user = eval("(" + localStorage.getItem("user") + ")");
        var id = user.id;
        var text = $('#text').val();

        var remind = "";
        if ($('#s').is(':checked')) {
            remind = new Date(Date.parse(time)).format("yyyy-MM-dd hh:mm:ss");
            var time = $('#remind').val();
            var now = new Date();
            var y = now.getFullYear(),
                m = ("0" + (now.getMonth() + 1)).slice(-2),
                d = ("0" + now.getDate()).slice(-2);
            var h = now.getHours(),
                mm = now.getMinutes(),
                s = now.getSeconds();
            var t = y + "-" + m + "-" + d + "T" + h + ":" + mm + ":" + s;
            var s = new Date(document.getElementById('remind').value).getTime();
            var p = new Date(t).getTime();

        }

        if ($('#d').is(':checked')) {
            remind = null;
        }

        if (text == null || text == "") {
            alert("请输入内容");
        }else{
          if (p > s) {
              alert("设置时间必须大于当前时间");
          } else {
              $.ajax({
                  type: "post",
                  url: URL + "edit/addMemo",
                  dataType: "json",
                  data: {
                      "id": id,
                      "msg": text,
                      "remind": remind,
                  },
                  success: function(data) {

                      var result = eval("(" + data + ")");

                      api.closeWin({

                      });

                      api.execScript({
                          name: 'memo_win',
                          frameName: 'memo_frm',
                          script: 'location.reload(true);'
                      });

                  },
                  error: function() {
                      alert("error");
                  }
              });
          }
        }

    }
</script>
<script type="text/javascript">

$("#text").focus(function(){
    window.onkeyup=function () {
        var content = $("#text").val();
        checkLength(content,200);
    }
})
//字符统计
function  getStringLen(Str){
    var   i,len,code;
    if(Str==null || Str == "" ||Str == " "||Str == "  "  )   return   0;
    len   =   Str.length;
    for   (i   =   0;i   <   Str.length;i++)
    {
        code   =   Str.charCodeAt(i);
        if   (code   >   255) {len ++;}
    }
    return   len;
}


function checkLength(value,length){
    var len = getStringLen(value);
    var numberLength=document.getElementById('contentLength');
    numberLength.innerText=(len)+'/'+(length);
}
</script>



</html>
